package com.chl.tools;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

public class Ole10NativeParser {
    
    public static void parseOle10Native(byte[] oleData) {
        ByteBuffer buffer = ByteBuffer.wrap(oleData).order(ByteOrder.LITTLE_ENDIAN);
        
        // 读取标签
        int tag = buffer.getInt();
        if (tag != 1) {
            throw new IllegalArgumentException("无效的Ole10Native标签");
        }
        
        // 读取文件名
        int filenameLength = buffer.getInt();
        byte[] filenameBytes = new byte[filenameLength];
        buffer.get(filenameBytes);
        String filename = new String(filenameBytes, StandardCharsets.UTF_16LE);
        
        // 读取文件路径
        int pathLength = buffer.getInt();
        byte[] pathBytes = new byte[pathLength];
        buffer.get(pathBytes);
        String path = new String(pathBytes, StandardCharsets.UTF_16LE);
        
        // 剩余部分是文件数据
        byte[] fileData = new byte[buffer.remaining()];
        buffer.get(fileData);
        
        System.out.println("原始文件名: " + filename);
        System.out.println("原始路径: " + path);
        System.out.println("文件大小: " + fileData.length + " 字节");
    }
}
